package com.holly.unit.bpmn.modular.activiti.controller;

import com.holly.unit.bpmn.activiti.ActivitiOperator;
import com.holly.unit.core.pojo.response.ErrorResponseData;
import com.holly.unit.core.pojo.response.ResponseData;
import com.holly.unit.core.pojo.response.SuccessResponseData;
import com.holly.unit.scanner.api.annotation.ApiResource;
import com.holly.unit.scanner.api.annotation.GetResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.FlowElement;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * 类描述: 蒙牛业务需求 【使用流程模型作为工艺路线】
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/6/16 8:17
 */
@RestController
@ApiResource(name = "蒙牛工艺业务相关API")
@Api(tags = "蒙牛工艺业务相关API")
@Slf4j
public class ArtWorkController {

    @Resource
    private ActivitiOperator operator;

    @ApiOperation("根据流程模型id获取流程元素【不包含子流程】")
    @GetResource(name = "根据流程模型id获取流程元素【不包含子流程】", path = "/biz/flowElement/{id}",requiredLogin = false,requiredPermission = false)
    public ResponseData getFlowElementByModelId(@PathVariable("id")String id) {

        Collection<FlowElement> ans = null;
        try {
            ans = operator.getFlowElementByModelId(id);
        } catch (Exception e) {
            return new ErrorResponseData("9500100","根据模型id获取FlowElement出错,id:::"+id);
        }
        return new SuccessResponseData(ans);
    }

    @ApiOperation("根据流程模型id获取流程模型")
    @GetResource(name = "根据流程模型id获取流程模型", path = "/biz/bpmnModel/{id}",requiredLogin = false,requiredPermission = false)
    public ResponseData getBpmnModelByModelId(@PathVariable("id")String id) {

        BpmnModel ans = null;
        try {
            ans = operator.getBpmnModelByModelId(id);
        } catch (Exception e) {
            return new ErrorResponseData("9500101","根据模型id获取BpmnModel出错,id:::"+id);
        }
        return new SuccessResponseData(ans);
    }

}
